package com.tma.demo;

public class Utils {
    /**
     * Convert time in miliseconds to day h:m:s ms format
     * 
     * @param milisecond
     *            the time in milisecond
     * @return the string represent time
     */
    public static String toDebugString(long milisecond) {
        if (milisecond == 0) {
            return "0 ms";
        }

        long ms = milisecond % 100;
        long t = milisecond / 1000;
        long second = t % 60;
        t = t / 60;
        long minute = t % 60;
        t = t / 60;
        long hour = t % 24;
        t = t / 24;
        long day = t;

        if (day > 0)
            return String.format("%d %2d:%2d:%2d %3d", day, hour, minute,
                    second, ms);
        if (hour > 0)
            return String.format("%d:%2d:%2d %3d", hour, minute, second, ms);
        if (minute > 0)
            return String.format("0:%2d:%2d %3d", hour, minute, second, ms);

        return String.format("%d ms", milisecond);
    }
}
